package com.gjy.rocketmq.product;

import com.gjy.rocketmq.RocketUtil;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeUnit;

/**
 * 延迟消息
 * 投递等级（delay level）	延迟时间	投递等级（delay level）	延迟时间
 * 1	1s	10	6min
 * 2	5s	11	7min
 * 3	10s	12	8min
 * 4	30s	13	9min
 * 5	1min	14	10min
 * 6	2min	15	20min
 * 7	3min	16	30min
 * 8	4min	17	1h
 * 9	5min	18	2h
 *
 * @author 宫静雨
 * @version 1.0
 * @since 2023-01-29 10:01:56
 */
public class DelayProduct {

    public static void main(String[] args) throws Exception {
        DefaultMQProducer producer = new DefaultMQProducer(RocketUtil.ProducerGroup);
        producer.setNamesrvAddr(RocketUtil.NAME_SRV);
        producer.start();

        for (int i = 0; i < 10; i++) {
            Message message = new Message(RocketUtil.TOPIC_TEST, "HHH".getBytes(StandardCharsets.UTF_8));
            message.setDelayTimeLevel(3);
            producer.send(message);
        }

        TimeUnit.SECONDS.sleep(Integer.MAX_VALUE);
        producer.shutdown();
    }
}
